from django.shortcuts import render
from django.http import HttpResponse
import time
from np01 import analist




# Create your views here.

REMOTE_HOST = "https://pyecharts.github.io/assets/js"


# def index(request):
#     index = '''\
#
#         <h1>XX同学</h1>
#
#         <hr>
#
#         <h2>ChipotleNan 数据分析</h2>
#
#         <h3>
#
#         <a href = '1/'>生成每种商品销售次数的bar图</a><br>
#         <a href = '2/'>生成每种商品销售金额的bar图</a><br>
#
#         </h3>
#
#         <hr>
#
#         <h2>电影类的 数据分析</h2>
#
#
#
#     '''
#     ti = time.time()
#     request.session['time'] = ti
#     return HttpResponse(index)

# 这段时间内餐厅的销售流水总额

# 首页
def index4(request):
    chipo=analist.ChipotleNan()
    bar=chipo.this_time_sold_brand_total_yuan()
    return render(request,'haha.html',{'bar':bar})


# 这段时间内销售个数最多的商品
def index(request):
    chipo=analist.ChipotleNan()
    ak=chipo.df.columns
    nkm=chipo.this_time_sold_brand_very_kind()

    return render(request,'home.html',{'nk':nkm,'ak':ak})

#这段时间内销售金额最多的商品
def sold_brand_too_much_money(request):
    chipo = analist.ChipotleNan()
    nkm = chipo.this_time_sold_money_very_duo()
    ck = chipo.this_time_sold_money_very_duo().columns
    return render(request, 'home.html', {'uk': nkm,'ck':ck})


 # 生成每种商品销售次数的bar图
def index1(request):
    chipo = analist.ChipotleNan()

    bar = chipo.bar_how_many_are_sold_per_item()

    context = dict(

        myechart=bar.render_embed(),

        host=REMOTE_HOST,

        script_list=bar.get_js_dependencies()
    )

    return render(request, 'index.html', context)

# 生成每种商品销售金额的bar图
def index2(request):
    chipo = analist.ChipotleNan()

    bar = chipo.bar_how_much_are_sold_per_item()  # 生成每种商品销售金额的bar图

    context = dict(

        myechart=bar.render_embed(),

        host=REMOTE_HOST,

        script_list=bar.get_js_dependencies()
    )

    return render(request, 'index.html', context)


# 餐厅的产品的种类及对应的商品配料的价格，做出表格

def pruduct_kind_and_good_price(request):
    chipo=analist.ChipotleNan()
    aum=chipo.product_kinds_and_brand_material_price_to_exls()
    # hua=chipo.product_kinds_and_brand_material_price_to_exls().columns
    list=[]
    for i in range(0, 1915):
        aa=aum.index[i]
        list.append(aa)

    return render(request,'home.html',{'aum':aum.index,'num':list})

# 每种商品销售金额在流水总额中所占的比例，做圆饼图
def per_goods_in_total_money_rate(request):
    return render(request,'render.html')


# 每个定单金额，并做bar图
def per_order_monet(request):
    return render(request,'order.html')


# 产品“ChickenBowl”, 选择最多的配料
def most_material_select(request):
    chipo=analist.ChipotleNan()
    hun=chipo.mater_chichenBowl_is_most()
    return render(request,'home.html',{'hun':hun})


# 产品“ChickenBowl”每种配料选择的次数，及所占比例，并做圆饼图

def select_most_material(request):
    return render(request,'material.html')